<?php

namespace app\api\controller;

use \think\Request;
use app\common\business\User as UserBn;
use app\common\business\user\Point as pointModel;
use \app\common\validate\UserLogin;
use app\common\business\upload\Upload as uploadBn;
use app\common\business\Quicklogin as quickloginBn;
use app\common\mysql\Users as usersMysql;

class User extends \app\common\controller\HomeBase {
    
    /*
     *
     * 注册第一步判断手机号以及验证码控制器
     *
     */

    public function register() {
        try {
            $params = input();
              $validate = Validate('UserLogin');
            $post = $validate->scene('register')->check($params);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            
            $data = UserBn::register($post);
            $this->_echoSuccessMessage('登录成功', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /*
     *
     * 验证码控制器
     *
     */

    public function codebutton() {
        try {

            $params = input();
            $validate = Validate('UserLogin');
            $post = $validate->scene('codebutton')->check($params);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            $post['user_id'] = $this->_isLogin();
            $data = UserBn::codebutton($post);
            $this->_echoSuccessMessage('发送成功', array("status" => true));
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 用户绑定
     */
    public function quickloginbind() {
        try {
            $user_id = $this->_validLogin();
            $post = input();
            $validate = Validate('UserLogin');
            $post = $validate->scene('quickloginbind')->check($post);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            $post['user_id'] = $user_id;
            $data = quickloginBn::quickLoginBind($post);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 当前用户是否已有手机号
     */
    public function checkmobile() {
        try {
            $user_id = $this->_validLogin();
            $data = quickloginBn::checkmobile($user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
//    /**
//     * 当前用户是否已有手机号
//     */
//    public function usersso() {
//        try {
//            $user_id = input('user_id');
//            $data = UserBn::calcSso($user_id);
//            echo $data;
//            $this->_echoSuccessMessage('', $data);
//        } catch (\Exception $e) {
//            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
//        }
//    }
}
